/*q2LCmxM8POvl78IL0LiydsmT0Boq1KyegAbxA8dmXl8=*/
import { ajax, toast, printer, cardCache, promptBox } from 'nc-lightapp-front';
import { billType, tradeType, dataSource, searchId, tableId,pkname } from '../constants';
import { headButton } from '../../../../public/components/pubUtils/buttonName.js';
import { getTransferInfo } from '../../../../public/components/pubUtils/transferButtonUtil.js';
import { imageScan, imageView } from 'sscrp/rppub/components/image';
import arapLinkReport from '../../../../public/components/arapBillLinkReport.js';
import linkvouchar from '../../../../public/components/linkvouchar.js';
import madeBill from '../../../../public/components/madeBill.js';
import { getContext, loginContextKeys } from '../../../../public/components/arapInitInfo/loginContext';
import { batchGenerate, batchSendSpAndCancelSenSPPubFun } from '../../../../public/components/pubUtils/billPubUtil.js';
import IndependentSettleUtil from 'sp/pub/utils/IndependentSettleUtil';
import { moduleEnable, IMAG } from '../../../../public/components/moduleEnable.js';
import {ListAllocperiodruleLinkQuery} from '../../../../public/components/allocation.js';
let { getDefData, setDefData } = cardCache;
import linkSourceList from '../../../../public/components/linkSourceList.js';
import updateTableDataTs,{getAllCheckedDataNew,deleteTableRowsByRowIds,deleteCachePKAndTS} from '../../../../public/components/updateTableDataTs';
export default function buttonClick(props, id) {
	const { openToIndepSettle } = IndependentSettleUtil;
	let code = getContext(loginContextKeys.transtype);
	let pagecode = props.getSearchParam('p');
	this.dataInSaga.butncode = id;
	switch (id) {
		case headButton.Add:
			pagecode = getDefData('sessionTradeType', dataSource);
			if (code) {
				pagecode = code;
			} else if (!pagecode) {
				pagecode = tradeType;
			}
			props.pushTo('/card', {
				status: 'add',
				pagecode: pagecode
			});
			break;
		case headButton.Commit: // 批量提交
			commitOpreration(this, this.props, this.tableId, billType, headButton.Commit);
			break;
		case headButton.Uncommit: // 批量收回
			commitOpreration(this, this.props, this.tableId, billType, headButton.Uncommit);
			break;
		case headButton.Generate://生成
			batchGenerate(this)
			break;
		case headButton.SendSP://传结算
			batchSendSpAndCancelSenSPPubFun(this, 1)
			break;
		case headButton.CancelSendSP://取消传结算
			batchSendSpAndCancelSenSPPubFun(this, 2)
			break;
		case headButton.Delete:
			promptBox({
				color: 'warning',
				title: this.state.json['paybill-000002'] /* 国际化处理： 删除*/,
				content: this.state.json['paybill-000052'] /* 国际化处理： ​确定要删除所选数据吗？*/,
				noFooter: false,
				noCancelBtn: false,
				beSureBtnName: this.state.json['paybill-000004'] /* 国际化处理： 确定*/,
				cancelBtnName: this.state.json['paybill-000005'] /* 国际化处理： 取消*/,
				beSureBtnClick: () => {
					// let delObjs = getAllCheckedData.call(this, this.props, this.tableId, billType);
					let {delObjs ,rowIds}= getAllCheckedDataNew.call(this, this.props, this.tableId, billType,pkname);
					if (delObjs.length == 0) {
						toast({ color: 'warning', content: this.state.json['paybill-000012'] }); /* 国际化处理： 请选中至少一行数据!*/
						return;
					}
					// if (delObjs.length == 1) {
					// 	this.Info.pk_bill = delObjs[0].pk_bill;
					// 	this.Info.ts = delObjs[0].ts;
					// 	this.Info.index = delObjs[0].index;
					// 	this.delConfirm();
					// } else {
						ajax({
							url: '/nccloud/arap/arappub/delete.do',
							data: delObjs,
							success: (res) => {
								let { success, data } = res;
								if (success) {
									if (data) {
										toast({
											duration: 'infinity',
											color: data.PopupWindowStyle,
											content: data.errMsg
										});

										//删除当前行数据
										// props.table.deleteTableRowsByIndex(tableId, data.successIndexs);
										deleteTableRowsByRowIds.call(this,{props,data,rowIds,tableId});
										//删除缓存数据
										if(data.successPKs){
											// props.table.deleteCacheId(tableId, data.successPKs);
											deleteCachePKAndTS.call(this,{props,tableId,successPKs:data.successPKs,checkedRows:delObjs,pkId:'pk_bill',pkname});
										}
										//列表控制按钮
										this.onSelected();
									}
								}
							}
						});
					// }
				}
			});

			break;
		case headButton.Push:
			promptBox({
				color: 'warning',
				title: '推送',
				content: '确定要推送所选数据吗？',
				noFooter: false,
				noCancelBtn: false,
				beSureBtnName: this.state.json['paybill-000004'] /* 国际化处理： 确定*/,
				cancelBtnName: this.state.json['paybill-000005'] /* 国际化处理： 取消*/,
				beSureBtnClick: () => {
					// let delObjs = getAllCheckedData.call(this, this.props, this.tableId, billType);
					let {delObjs ,rowIds}= getAllCheckedDataNew.call(this, this.props, this.tableId, billType,pkname);
					if (delObjs.length == 0) {
						toast({ color: 'warning', content: this.state.json['paybill-000012'] }); /* 国际化处理： 请选中至少一行数据!*/
						return;
					}
					// if (delObjs.length == 1) {
					// 	this.Info.pk_bill = delObjs[0].pk_bill;
					// 	this.Info.ts = delObjs[0].ts;
					// 	this.Info.index = delObjs[0].index;
					// 	this.delConfirm();
					// } else {
					ajax({
						url: '/nccloud/arap/arappub/push.do',
						data: delObjs,
						success: (res) => {
							let { success, data } = res;
							if (success) {
								if (data) {
									toast({
										duration: 'infinity',
										color: data.PopupWindowStyle,
										content: data.errMsg
									});
									//删除当前行数据
									// props.table.deleteTableRowsByIndex(tableId, data.successIndexs);
									deleteTableRowsByRowIds.call(this,{props,data,rowIds,tableId});
									//删除缓存数据
									if(data.successPKs){
										// props.table.deleteCacheId(tableId, data.successPKs);
										deleteCachePKAndTS.call(this,{props,tableId,successPKs:data.successPKs,checkedRows:delObjs,pkId:'pk_bill',pkname});
									}
									//列表控制按钮
									this.onSelected();
								}
							}
						}
					});
					// }
				}
			});

			break;
		case headButton.MadeBill: //制单
			madeBill(
				this,
				props,
				this.props.table.getCheckedRows(this.tableId,false),
				'pk_paybill',
				props.getSearchParam('c'),
				true
			);
			break;
		case headButton.BillLinkQuery: //联查单据
			let selectInfo = getFirstCheckedData.call(this,this.props, this.tableId);
			this.Info.pk_bill = selectInfo.data.values.pk_paybill.value;
			this.Info.pk_tradetype = selectInfo.data.values.pk_tradetype.value;
			this.setState({
				showBillTrack: true
			});
			break;
		case headButton.LinkInvoice: //发票查看
			if (!moduleEnable(this, IMAG)) { //校验关联模块是否启用
				return;
			}
			this.setState({ showSSCmodule: true });
			let InvoiceInfo = getFirstCheckedData.call(this,this.props, this.tableId);
			const billId = InvoiceInfo.data.values.pk_paybill.value;
			const billtype = InvoiceInfo.data.values.pk_billtype.value;
			const billCode = InvoiceInfo.data.values.billno.value;
			const pk_org = InvoiceInfo.data.values.pk_org.value;
			const tradetype = InvoiceInfo.data.values.pk_tradetype.value;
			const viewRandom = new Date().getTime();

			this.setState({
				sscivmInvoiceData: { billId, billtype, billCode, pk_org, tradetype, viewRandom }
			});
			break;
		case headButton.LinkAprv: //审批详情
			let LinkAprvData = this.props.table.getCheckedRows(this.tableId,false)[0];
			if (LinkAprvData) {
				this.Info.pk_bill = LinkAprvData.data.values.pk_paybill.value;
				this.Info.pk_tradetype = LinkAprvData.data.values.pk_tradetype.value;
				this.setState({
					showApproveDetail: true
				});
			} else {
				toast({ color: 'warning', content: this.state.json['paybill-000029'] }); /* 国际化处理： 请选中一行数据!*/
			}
			break;
		case headButton.ConnectSettleInfo: //关联结算信息
			ajax({
				url: '/nccloud/arap/arappub/validatecmp.do',
				data: null,
				success: (res) => {
					if (res.success) {
						pagecode = getDefData('sessionTradeType', dataSource);
						if (code) {
							pagecode = code;
						} else if (!pagecode) {
							pagecode = tradeType;
						}

						openToIndepSettle({
							props,
							direction: "1",
							pk_billtypecode:"F3",
							rollbackAppcode: props.getSearchParam('c'),
							rollbackPageCode: pagecode
						})
					}
				}
			});
			break;
		case headButton.LinkInformer: //到账通知
			let InformerInfo = getFirstCheckedData.call(this,this.props, this.tableId);
			ajax({
				url: '/nccloud/arap/arappub/linkinformer.do',
				data: Object.assign({
					pk_bill: InformerInfo.data.values.pk_paybill.value,
					billType: billType
				}, this.dataInSaga),
				success: (res) => {
					if (res.success && res.data) {
						let length = res.data.length;
						if (length == 1) {
							props.openTo('/nccloud/resources/cmp/informer/LinkBill/card/index.html', {
								appcode: '36070AISC',
								pagecode: '36070AILLINK',
								status: 'browse',
								id: res.data
							});
						} else {
							props.openTo('/nccloud/resources/cmp/informer/LinkBill/list/index.html', {
								appcode: '36070AISC',
								pagecode: '36070AICLINK',
								status: 'browse',
								ids: res.data
							});
						}
					}
				}
			});
			break;
		case headButton.LinkBal: //联查余额表
			let linkBalInfo = getFirstCheckedData.call(this,this.props, this.tableId);
			arapLinkReport(
				this.props,
				linkBalInfo.data.values.pk_paybill.value,
				billType,
				linkBalInfo.data.values.objtype.value,
				linkBalInfo.data.values.pk_org_v
			);
			break;
		case headButton.LinkDeal: //联查处理情况
			let dealInfo = getFirstCheckedData.call(this,this.props, this.tableId);
			ajax({
				url: '/nccloud/arap/arappub/linkdeal.do',
				data: Object.assign({
					pk_bill: dealInfo.data.values.pk_paybill.value,
					ts: dealInfo.data.values.ts.value,
					billType: billType
				}, this.dataInSaga),
				success: (res) => {
					if (res.success) {
						//打开处理情况模态框
						let data = res.data;
						//当前选中数据的第一行的交易类型和单据号，用于联查处理情况的模态框上面的显示
						let checkedData = this.props.table.getCheckedRows(this.tableId,false)[0].data.values;
						this.Info.combinedExaminationData = data;
						this.Info.pk_tradetypeid = checkedData.pk_tradetypeid
							? checkedData.pk_tradetypeid.display
							: null;
						this.Info.billno = checkedData.billno ? checkedData.billno.value : null;

						this.handleCombined();
					}
				}
			});
			break;
		case headButton.LinkVouchar: //联查凭证
			let voucharInfo = getFirstCheckedData.call(this,this.props, this.tableId);
			linkvouchar(this, props, voucharInfo, voucharInfo.data.values.pk_paybill.value, props.getSearchParam('c'));
			break;
		case headButton.LinkConfer: //联查协同单据
			let conferInfo = getFirstCheckedData.call(this,this.props, this.tableId);
			ajax({
				url: '/nccloud/arap/arappub/linkconfer.do',
				async: false,
				data: Object.assign({
					pk_bill: conferInfo.data.values.pk_paybill.value,
					billType: billType
				}, this.dataInSaga),
				success: (res) => {
					let data = res.data;
					if (data) {
						props.openTo(data.url, data.condition);
					}
				}
			});
			break;
		case headButton.LinkTbb: //联查计划预算
			let tbbInfo = getFirstCheckedData.call(this,this.props, this.tableId);
			ajax({
				url: '/nccloud/arap/arappub/linktbb.do',
				data: {
					pk_bill: tbbInfo.data.values.pk_paybill.value,
					billType: billType
				},
				success: (res) => {
					this.Info.tbbLinkSourceData = res.data;
					this.setState({
						isTbbLinkshow: true
					});
				}
			});
			break;
		case headButton.Print: //打印
			let printData = this.props.table.getCheckedRows(this.tableId);
			if (printData.length == 0) {
				toast({ color: 'warning', content: this.state.json['paybill-000029'] }); /* 国际化处理： 请选中一行数据!*/
				return;
			}
			let pk_bills = [];
			printData.forEach((val) => {
				pk_bills.push(val.data.values ? val.data.values.pk_paybill.value : val.data.pk);
			});
			this.printData.oids = pk_bills;
			this.printData.nodekey = 'card';
			this.onPrint();
			break;
		case headButton.PrintList: //打印清单
			printData = this.props.table.getCheckedRows(this.tableId);
			pk_bills = [];
			printData.forEach((val) => {
				pk_bills.push(val.data.values ? val.data.values.pk_paybill.value : val.data.pk);
			});
			if (pk_bills.length == 0) {
				toast({ color: 'warning', content: this.state.json['paybill-000029'] }); /* 国际化处理： 请选中一行数据!*/
				return;
			}
			this.printData.oids = pk_bills;
			this.printData.nodekey = 'list';
			// printer(
			// 	'pdf', //支持两类: 'html'为模板打印, 'pdf'为pdf打印
			// 	'/nccloud/arap/arappub/print.do', //后台服务url
			// 	this.printData
			// );
			this.printPreviewBill(true);
			break;
		case headButton.Output: //打印输出
			printData = this.props.table.getCheckedRows(this.tableId);
			if (printData.length == 0) {
				toast({ color: 'warning', content: this.state.json['paybill-000029'] }); /* 国际化处理： 请选中一行数据!*/
				return;
			}
			pk_bills = [];
			printData.forEach((val) => {
				pk_bills.push(val.data.values ? val.data.values.pk_paybill.value : val.data.pk);
			});
			this.outputData.oids = pk_bills;
			this.outputData.nodekey = 'card';
			this.printOutput();
			break;
		case headButton.OutputList: //输出清单
			printData = this.props.table.getCheckedRows(this.tableId);
			if (printData.length == 0) {
				toast({ color: 'warning', content: this.state.json['paybill-000029'] }); /* 国际化处理： 请选中一行数据!*/
				return;
			}
			pk_bills = [];
			printData.forEach((val) => {
				pk_bills.push(val.data.values ? val.data.values.pk_paybill.value : val.data.pk);
			});
			this.outputData.oids = pk_bills;
			this.outputData.nodekey = 'list';
			this.printOutput();
			break;
		case headButton.OfficalPrint: //正式打印
			printData = this.props.table.getCheckedRows(this.tableId);
			if (printData.length == 0) {
				toast({ color: 'warning', content: this.state.json['paybill-000029'] }); /* 国际化处理： 请选中一行数据!*/
				return;
			}
			pk_bills = [];
			printData.forEach((val) => {
				let pkBill = val.data.values ? val.data.values.pk_paybill.value : val.data.pk;
				pk_bills.push(pkBill+"_"+val.index);
			});
			this.printData.oids = pk_bills;
			this.printData.nodekey = 'card';
			this.officalPrintOutput();
			break;
		case headButton.CancelPrint: //取消正式打印
			printData = this.props.table.getCheckedRows(this.tableId);
			if (printData.length == 0) {
				toast({ color: 'warning', content: this.state.json['paybill-000029'] }); /* 国际化处理： 请选中一行数据!*/
				return;
			}
			pk_bills = [];
			printData.forEach((val) => {
				let pkBill = val.data.values ? val.data.values.pk_paybill.value : val.data.pk;
				pk_bills.push(pkBill+"_"+val.index);
			});
			this.printData.oids = pk_bills;
			this.printData.nodekey = 'card';
			this.cancelPrintOutput();
			break;
		case headButton.ExportData: //导出
			if (this.state.forceRender) {
				this.setState({ forceRender: false })
			}
			let outputData = this.props.table.getCheckedRows(this.tableId);
			pk_bills = [];
			outputData.forEach((val) => {
				pk_bills.push(val.data.values ? val.data.values.pk_paybill.value : val.data.pk);
			});
			if (pk_bills.length == 0) {
				toast({ color: 'warning', content: this.state.json['paybill-000029'] }); /* 国际化处理： 请选中一行数据!*/
				return;
			}
			this.Info.selectedPKS = pk_bills; //传递主键数组,之前nc需要导出的加主键
			this.props.modal.show('exportFileModal'); //不需要导出的只执行这行代码
			break;
		case headButton.Refresh: //刷新
			let data = getDefData(searchId, dataSource);
			if (data) {
				data.queryInfo.pageInfo = this.props.table.getTablePageInfo(this.tableId);//重新获取分页信息
				ajax({
					url: '/nccloud/arap/paybill/queryscheme.do',
					data: Object.assign(data, this.dataInSaga),
					success: (res) => {
						let { success, data } = res;
						if (success) {
							if (data) {
								toast({ color: 'success', title: this.state.json['paybill-000051'] }); /* 国际化处理： 刷新成功*/
								this.props.table.setAllTableData(this.tableId, data[this.tableId]);
								setDefData(this.tableId, dataSource, data); //放入缓存
							    this.onSelected();
							} else {
								toast({ color: 'success', title: this.state.json['paybill-000051'] }); /* 国际化处理： 刷新成功*/
								this.props.table.setAllTableData(this.tableId, { rows: [] });
							}
							
						}
					}
				});
			}else if ('browse' == this.props.getUrlParam('status')&&'fip' == this.props.getUrlParam('scene')) {
				//联查
				linkSourceList(this.props, this.tableId);
			} else {
				toast({ color: 'success', title: this.state.json['paybill-000051'] }); /* 国际化处理： 刷新成功*/
				this.props.table.setAllTableData(this.tableId, { rows: [] });
			}
			break;
		case headButton.ReceiptCheck: //影像查看pk_tradetype
			if (!moduleEnable(this, IMAG)) { //校验关联模块是否启用
				return;
			}
			let CheckInfo = getFirstCheckedData.call(this,this.props, this.tableId);

			var billInfoMap = {};

			//基础字段 单据pk,单据类型，交易类型，单据的组织
			billInfoMap.pk_billid = CheckInfo.data.values.pk_paybill.value;
			billInfoMap.pk_billtype = CheckInfo.data.values.pk_billtype.value;
			billInfoMap.pk_tradetype = CheckInfo.data.values.pk_tradetype.value;
			billInfoMap.pk_org = CheckInfo.data.values.pk_org.value;
			imageView(billInfoMap, 'iweb');
			break;
		case headButton.ReceiptScan: //影像扫描
			if (!moduleEnable(this, IMAG)) { //校验关联模块是否启用
				return;
			}
			let ScanInfo = getFirstCheckedData.call(this,this.props, this.tableId);

			var billInfoMap = {};

			//基础字段 单据pk,单据类型，交易类型，单据的组织
			billInfoMap.pk_billid = ScanInfo.data.values.pk_paybill.value;
			billInfoMap.pk_billtype = ScanInfo.data.values.pk_billtype.value;
			billInfoMap.pk_tradetype = ScanInfo.data.values.pk_tradetype.value;
			billInfoMap.pk_org = ScanInfo.data.values.pk_org.value;

			//影像所需 FieldMap
			billInfoMap.BillType = ScanInfo.data.values.pk_tradetype.value;
			billInfoMap.BillDate = ScanInfo.data.values.creationtime.value;
			billInfoMap.Busi_Serial_No = ScanInfo.data.values.pk_paybill.value;
			// billInfoMap.pk_billtype = billdata.head.head.rows[0].values.pk_billtype.value;
			billInfoMap.OrgNo = ScanInfo.data.values.pk_org.value;
			billInfoMap.BillCode = ScanInfo.data.values.billno.value;
			billInfoMap.OrgName = ScanInfo.data.values.pk_org_v.display;
			billInfoMap.Cash = ScanInfo.data.values.money.value;
			imageScan(billInfoMap, 'iweb');
			break;
		case headButton.AttachManage:
			let AttachInfo = getFirstCheckedData.call(this,this.props, this.tableId);
			this.Info.pk_bill = AttachInfo.data.values.pk_paybill.value;
			this.Info.billno = AttachInfo.data.values.billno.value;
			//设置付款框左侧分组
			setBillConfig(this);
			this.setState({
				showUploader: true,
				target: null
			});
			break;
		case headButton.AllocperiodruleLinkQuery:
			ListAllocperiodruleLinkQuery(this);
			break;
		default:
			let transferInfo = getTransferInfo(this, id);
			if (transferInfo) {
				ajax({
					url: '/nccloud/arap/arappub/queryrelatedapp.do',
					data: {
						billType: transferInfo.src_billtype,
						transTypes: transferInfo.transtypes
					},
					success: (res) => {
						if (res) {
							//将业务流程放入缓存
							setDefData(
								transferInfo.src_billtype + transferInfo.transtypes[0],
								'transfer.dataSource',
								transferInfo.busitypes
							);
							let dest_tradetype = getDefData('sessionTradeType', dataSource);
							if (code) {
								dest_tradetype = code;
							} else if (!dest_tradetype) {
								dest_tradetype = tradeType;
							}
							let url = '/' + transferInfo.src_billtype;
							props.pushTo(url, {
								//appcode:res.data.appcode,
								src_appcode: res.data.appcode,
								src_tradetype: transferInfo.transtypes[0], //来源交易类型
								dest_billtype: billType,
								dest_tradetype: dest_tradetype
							});
						}
					}
				});
			}
			break;
	}
}

//获取选中数据的第一行,选中多行的时候只取第一行数据
let getFirstCheckedData = function (props, tableId) {
	let checkedData = props.table.getCheckedRows(tableId,false);
	let checkedObj;
	if (checkedData.length > 0) {
		checkedObj = checkedData[0];
	} else {
		toast({ color: 'warning', content: this.state.json['paybill-000029'] }); /* 国际化处理： 请选中一行数据!*/
		return;
	}
	return checkedObj;
};

//获取选中数据的id和billType
let getAllCheckedData = function (props, tableId, billType) {
	let checkedData = props.table.getCheckedRows(tableId);
	let checkedObj = [];
	checkedData.forEach((val) => {
		checkedObj.push(Object.assign({
			pk_bill: val.data.values ? val.data.values.pk_paybill.value : val.data.pk,
			billno: val.data.values?val.data.values.billno.value:val.data.billno,
			ts: val.data.values ? val.data.values.ts.value : val.data.ts,
			billType: billType,
			index: val.index,
			rowid:val.data&&val.data.rowid?val.data.rowid:'',
			pageId: props.getSearchParam('p')
		}, this.dataInSaga));
	});
	return checkedObj;
};

let commitOpreration = function (that, props, tableId, billType, actionType) {
	let commitParams = getAllCheckedData.call(that, props, tableId, billType);
	if (commitParams.length == 0) {
		toast({ color: 'warning', content: that.state.json['paybill-000012'] }); /* 国际化处理： 请选中至少一行数据!*/
		return;
	}
	let ajaxUrl = '';
	if (actionType == headButton.Commit) {
		ajaxUrl = '/nccloud/arap/arappub/batchcommit.do';
	} else if (actionType == headButton.Uncommit) {
		ajaxUrl = '/nccloud/arap/arappub/batchuncommit.do';
	}
	if (commitParams.length == 1 && actionType == headButton.Commit) {
		let checkedRows=props.table.getCheckedRows(tableId);
		//单条的时候走单条的处理
		that.Info.tipUrl = '/nccloud/arap/arappub/commit.do';
		that.Info.record = checkedRows[0].data.values?checkedRows[0].data.values:checkedRows[0].data;
		that.Info.record.numberindex = { scale: 0, value: commitParams[0].index + 1 };
		that.commitAndUncommit();
		return;
	}

	ajax({
		url: ajaxUrl,
		data: commitParams,
		success: (res) => {
			let { success, data } = res;
			if (success) {
				// if (data.grid) {
				// 	let grid = data.grid;
				// 	let updateValue = [];
				// 	for (let key in grid) {
				// 		updateValue.push({ index: key, data: { values: grid[key].values } });
				// 	}
				// 	props.table.updateDataByIndexs(tableId, updateValue);

				// 	props.table.selectAllRows(tableId, false) //由于平台没支持跨页 操作后updateDataByIndexs 取消跨页勾选，此处自己调一次全部取消勾选
				// }
				if(data&&data.grid){
					updateTableDataTs.call(that,{props,data,tableId});
				}
				if (data.message) {
					toast({
						duration: 'infinity',
						color: data.PopupWindowStyle,
						content: data.message
					});
					that.onSelected();
				}
			}
		}
	});
};


/**
 * qinwef 2022-0211
 * 加载附件管理左侧分组
 */
function setBillConfig(that) {
	let selectInfo = getFirstCheckedData.call(that,that.props, that.tableId);
	let billPK = selectInfo.data.values.pk_paybill.value;
	let billno = selectInfo.data.values.billno.value;
	let billType = selectInfo.data.values.pk_billtype.value;
	let nowBillTypeName = that.state.json['paybill-000064'];
	// if(billno!=null&&billno!='undefined'&&billno!='null'&&billno!=''){
	// 	nowBillTypeName=nowBillTypeName+billno;
	// }
	//初始设置：主单据
	that.Config.billConfig = [{
		billId: billPK,
		folderName: nowBillTypeName,
		disableButton:JSON.stringify( ["fs_group_delete","fs_group_edit"]),
		showtype: "SHOWTYPE20"
	},{
		billId:billPK+"/"+that.state.json['paybill-000066'],
		folderName: that.state.json['paybill-000066'],
		disableButton: JSON.stringify(  ["fs_group_add","fs_group_delete","fs_group_edit","fs_delete","fs_move","fs_edit","fs_upload"]),
		showtype: "SHOWTYPE40"
	}];
	
	//进行单据追溯，查询上游单据
	let datas = {
		"queryCondition": {
			"bill_PK": billPK,
			"bill_type": billType
		}
	};
	ajax({
		url: '/nccloud/baseapp/riart/billFlow/billFlowAction.do',
		data: datas,
		async:false,
		success: (res) => {
			let upBillInfo = res.data;
			let upBillIdList = [];
			let upBillTypeMap = new Map();
			let upBillTypeNameMap = new Map();
			let upBillnoMap = new Map();
			let upForwardMap = new Map();
			if (upBillInfo != null && upBillInfo.length > 0) {
				for (let i = 0; i < upBillInfo.length; i++) {
					let isForward = upBillInfo[i].isForward;
					let billId = upBillInfo[i].lightBillVO.billID;
					let billTypeName = upBillInfo[i].lightBillVO.billTypeName;
					let billType = upBillInfo[i].lightBillVO.billType;
					let billno= upBillInfo[i].lightBillVO.billCode;
					if (billId != null&&billPK!=billId&&isForward<0) {
						upBillIdList.push(billId);
						upBillTypeMap.set(billId, billType);
						upBillTypeNameMap.set(billId, billTypeName);
						upBillnoMap.set(billId,billno);
						upForwardMap.set(isForward);
					}
				}
			}
			if (upBillIdList != null && upBillIdList.length > 0) {
				for(let j=0;j<upBillIdList.length;j++){
					let pkbill=upBillIdList[j];
					let pk_billtype=upBillTypeMap.get(pkbill);
					let billcon = {
						billId: pkbill,
						folderName: upBillTypeNameMap.get(upBillIdList[j])+upBillnoMap.get(upBillIdList[j]),
						disableButton: JSON.stringify( ["fs_group_add","fs_group_delete","fs_group_edit","fs_delete","fs_move","fs_edit","fs_upload_url","fs_upload"]),
						showtype: "SHOWTYPE40"
					};
					that.Config.billConfig.push(billcon);
				}
			}
		}
	})

}
/*q2LCmxM8POvl78IL0LiydsmT0Boq1KyegAbxA8dmXl8=*/